﻿using System;
using System.Collections;
using System.Data;
using CE.Database;
using CE.Security;

/// <summary>
/// Summary description for ContactCallMeDB
/// </summary>
/// 
namespace CE.User
{
    public class ContactCallMeDB
    {
        public ContactCallMeDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(ContactCallMe contactcallme)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocContactCallMeDetailInsertUpdateSingleItem";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@IsExistingUser", contactcallme.IsExistingUser );
            _sPara.Add("@Email", contactcallme.Email);
            _sPara.Add("@FullName", contactcallme.FullName);
            _sPara.Add("@ContactNo", contactcallme.ContactNo);
            _sPara.Add("@CallTime", contactcallme.CallTime);
            _sPara.Add("@Status", contactcallme.Status);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        #region "Update"
        //public Int64 Update(Int64 CEID, Int64 AgentId, Int64 ProviderCompanyId, string ProductType, Int64 ProductId)
        //{
        //    MyDatabase _db = new MyDatabase();
        //    Int64 _result = -1;
        //    string _spName = "sprocContactCallMeDetailUpdateAgentIdSingleItem";

        //    SortedList _sPara = new SortedList();

        //    #region Parameter
        //    _sPara.Add("@CEID", CEID);
        //    _sPara.Add("@AgentId", AgentId);
        //    _sPara.Add("@ProviderCompanyId", ProviderCompanyId);
        //    _sPara.Add("@ProductType", ProductType);
        //    _sPara.Add("@ProductId", ProductId);
        //    #endregion

        //    _result = _db.ExecuteSP(_spName, _sPara);

        //    return _result;
        //}
        #endregion

        #region "GetCallMe"
        //public ContactCallMe GetCallMe(string Email)
        //{
        //    MyDatabase _Db = new MyDatabase();
        //    string _spName = "sprocContactCallMeSelectSingleItem";
        //    ContactCallMe _result = null;
        //    DataTable _dt;
        //    SortedList _sPara = new SortedList();

        //    _sPara.Add("@RefCEUserId", RefCEUserID);
        //    _sPara.Add("@ProductId", ProductId);
        //    _sPara.Add("@InsuranceType", InsType);
        //    _sPara.Add("@ProviderCompanyId", ProviderCompanyId);

        //    _dt = _Db.GetDataTableBySP(_spName, _sPara);

        //    if (_dt != null && _dt.Rows.Count > 0)
        //    {
        //        _result = new ContactCallMe();
        //        _result = FillDataRecord(_dt);
        //    }

        //    return _result;
        //}
        #endregion 

        private ContactCallMe FillDataRecord(DataTable myDataTable)
        {
            ContactCallMe myContact = new ContactCallMe();
            myContact.CallMeId = Convert.ToInt64(myDataTable.Rows[0]["CallMeId"].ToString());
            myContact.IsExistingUser  = Convert.ToBoolean(myDataTable.Rows[0]["IsExistingUser"].ToString());
            myContact.Email = myDataTable.Rows[0]["Email"].ToString();
            myContact.FullName = myDataTable.Rows[0]["FullName"].ToString();
            myContact.ContactNo = myDataTable.Rows[0]["ContactNo"].ToString();
            myContact.CallTime = Convert.ToInt16(myDataTable.Rows[0]["CallTime"].ToString());
            myContact.CreatedDate = Convert.ToDateTime(myDataTable.Rows[0]["CreatedDate"].ToString());
            myContact.ModifiedDate = Convert.ToDateTime(myDataTable.Rows[0]["ModifiedDate"].ToString());
            return myContact;
        }
    }
}